package mapproviderapi;

import java.io.Serializable;

public class MapTile implements Serializable {
	private String tileUrl;

	private MapTileBound bound;
	
	private int zoom;
	
	private Coordinate coordinate;
	
	public String getTileUrl() {
		return tileUrl;
	}

	public void setTileUrl(String tileUrl) {
		this.tileUrl = tileUrl;
	}

	public int getTileWidth() {
		return bound.getWidth();
	}

	public void setTileWidth(int tileWidth) {
		bound.setWidth(tileWidth);
	}

	public int getTileHeight() {
		return bound.getHeight();
	}

	public void setTileHeight(int tileHeight) {
		bound.setHeight(tileHeight);
	}

	public int getZoom() {
		return zoom;
	}

	public void setZoom(int zoom) {
		this.zoom = zoom;
	}

	public Coordinate getCoordinate(){
		return coordinate;
	}
	
	public void setCoordinate(Coordinate coordinate){
		this.coordinate = coordinate;
	}
	
	public void setTop(int top){
		bound.setTop(top);
	}
	
	public int getTop(){
		return bound.getTop();
	}
	
	public void setLeft(int left){
		bound.setLeft(left);
	}
	
	public int getLeft(){
		return bound.getLeft();
	}
	
	public MapTile(){
		coordinate = new Coordinate();
		bound = new MapTileBound();
	}
	
	public MapTile(Coordinate coordinate, String tileUrl, int tileWidth, int tileHeight, int zoom){
		this.coordinate = coordinate;
		this.tileUrl = tileUrl;
		bound = new MapTileBound(0, 0, tileWidth, tileHeight);	
	}
	
	@Override
	public int hashCode(){
		final int prime = 31;
		int result = 1;
		
		result *= prime + ((tileUrl == null) ? 0 : tileUrl.hashCode());
		result *= prime + ((bound == null) ? 0 : bound.hashCode());		
		result *= prime + zoom;
		result *= prime + ((coordinate == null) ? 0 : coordinate.hashCode());
		
		return result;
	}
	
	@Override
	public boolean equals(Object obj){
		if (this == obj){
			return true;
		}
		if (obj == null){
			return false;
		}
		if (this.getClass() != obj.getClass()){
			return false;
		}
		MapTile other = (MapTile) obj;
		if (tileUrl == null){
			if (other.tileUrl != null){
				return false;
			}
		}else if(!tileUrl.equals(other.tileUrl)){
			return false;
		}
		if (coordinate == null){
			if (other.coordinate != null){
				return false;
			}
		}else if (!coordinate.equals(other.coordinate)){
			return false;
		}
		if (!bound.equals(other.bound)){
			return false;
		}
		
		if (zoom != other.zoom){
			return false;
		}
		return true;
		
	}
	
}
